home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-06-19 | 31.1 KB | 648 lines |
- /*
- *
- * 28 1/30/97 1:02p Cthrons
- * Call super.setEditable on last line of "setEditable(ProjBinder)"
- *
- * 27 1/24/97 4:27p Tjones
- * Removed 'throws SQLException' from setbinding method
- *
- * 26 1/17/97 3:14p Tjones
- * Modified setBinding method to throw SQLException
- *
- * 25 1/17/97 2:53p Tjones
- * Fixed bug with setEditable
- *
- * 24 12/19/96 1:42p Tjones
- * Bug fix with the setTreatBlankAs method
- *
- * 23 12/16/96 9:45a Tjones
- * Added parameters to the call to setValueFromString.
- * Added setTreatAsBlank method.
- *
- * 22 12/08/96 4:31p Tjones
- * Make notifySetData throw SQLException and use binder.getStringValue
- * method.
- *
- * 21 12/07/96 6:18p Tjones
- * Changed return type of notifySetData to boolean.
- *
- * 20 12/06/96 3:27p Tjones
- * Added additional comments
- *
- * 19 12/06/96 7:30a Tjones
- * Fixed bug with clearing fields for new record.
- *
- * 18 12/05/96 9:03p Cthrons
- * Check for valid current record state before calling isReadable.
- *
- * 17 12/05/96 5:43p Tjones
- * A whole bunch of changes
- *
- * 16 11/27/96 5:24p Tjones
- *
- * 15 11/27/96 4:29p Tjones
- *
- * 14 11/27/96 8:41a Tjones
- *
- * 13 11/26/96 4:49p Tjones
- *
- * 12 11/26/96 4:33p Tjones
- * Added notifySetData()
- *
- * 11 11/25/96 2:39p Tjones
- *
- * 10 11/25/96 1:41p Tjones
- *
- * 9 11/25/96 1:29p Tjones
- * Introduced dynamic edit method
- *
- * 8 11/21/96 3:55p Tjones
- *
- * 7 11/21/96 3:53p Tjones
- * Reinstituted the setBinding method
- *
- * 6 11/14/96 8:22p Cthrons
- * Put in safety code to make sure binder is readable, writable, etc...
- *
- * 5 11/01/96 1:41p Cthrons
- * Process key input.
- *
- * 4 10/25/96 11:14p Kbradle
- * Remove internal setProjBinding routine (no longer needed)
- * Add calls so that the controls get the first record of data during
- * init().
- *
- * 3 10/15/96 7:27p Kbradle
- * Implement lostFocus and gotFocus which compares the values and only
- * sends data to scale if it changed.
- *
- * 2 10/11/96 7:01p Kbradle
- * change LostFocus to lostFocus (case typo)
- *
- * 1 10/03/96 11:59p Cthrons
- */
-
- package symantec.itools.db.awt;
-
- // import java.awt.*;
- import java.util.*;
- import symjava.sql.*;
- import java.lang.*;
- import symantec.itools.db.net.*;
- import symantec.itools.db.pro.*;
-
- //*************************************************************************//
- // //
- // CLASS: TextArea //
- // //
- // PURPOSE: A TextArea object is a multi-line area that displays text. //
- // It can be bound to a projection in a database. //
- // It can be set to allow editing or read-only modes. //
- // //
- // PARAMETERS: //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- //*************************************************************************//
-
- public class TextArea extends java.awt.TextArea implements ProjLink
- {
- private ProjBinder m_ProjBinder; // Object used to interact with server
-
- private boolean m_DynamicUpdate = false;
- private boolean m_DynamicUpdateOverride = true;
- private boolean m_BinderDetermines = true;
- private String m_BinderData; // Keep in synch with database
- private String m_ScreenData; // Keep in synch with screen text
- private int m_treatBlankAs =0;
-
- //*************************************************************************//
- // //
- // FUNCTION: TextArea //
- // //
- // PURPOSE: Default constructor //
- // //
- // PARAMETERS: //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- //*************************************************************************//
-
- public TextArea()
- {
- super();
- m_ScreenData = new String();
- m_BinderData = new String()
- ;
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: TextArea //
- // //
- // PURPOSE: //
- // * Constructs a new TextArea with the specified number of rows and columns.
- // //
- // PARAMETERS: //
- // * @param rows the number of rows //
- // * @param cols the number of columns //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- //*************************************************************************//
-
- public TextArea(int rows, int cols)
- {
- super(rows, cols);
- m_ScreenData = new String();
- m_BinderData = new String();
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: TextArea //
- // //
- // PURPOSE: //
- // * Constructs a new TextArea with the specified text. //
- // //
- // PARAMETERS: //
- // * @param text the text to be display //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- //*************************************************************************//
-
- public TextArea(String text)
- {
- super(text);
- m_ScreenData = new String();
- m_BinderData = new String();
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: TextArea //
- // //
- // PURPOSE: //
- // * Constructs a new TextArea with the specified text and number of columns.
- // and columns.
- // //
- // PARAMETERS: //
- // * @param text the text to be displayed //
- // * @param rows the number of rows //
- // * @param cols the number of columns //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- //*************************************************************************//
-
- public TextArea(String text, int rows, int cols)
- {
- super(text, rows, cols);
- m_ScreenData = new String();
- m_BinderData = new String();
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: init //
- // //
- // PURPOSE: //
- // //
- // PARAMETERS: //
- // @param binder The ProjBinder binder object which this component can use//
- // to change data at the database server. //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // Implement the ProjLink interface function, init(). //
- // This function is called when the control is first bound to data. //
- // //
- //*************************************************************************//
-
- public void init (ProjBinder binder)
- {
- m_ProjBinder = binder;
- setEditable(m_ProjBinder);
- }
-
- public void setTreatBlankAs(String blank)
- {
- if (new String(blank).toUpperCase().equals("DEFAULT"))
- {
- m_treatBlankAs = RelationView.SETBLANKTODEFAULT;
- }
- else if (new String(blank).toUpperCase().equals("NULL"))
- {
- m_treatBlankAs = RelationView.SETBLANKTONULL;
- }
- else if (new String(blank).toUpperCase().equals("BLANK"))
- {
- m_treatBlankAs = RelationView.SETBLANKTOEMPTY;
- }
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: setBinding //
- // //
- // PURPOSE: //
- // //
- // PARAMETERS: //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- //*************************************************************************//
-
- public void setBinding(RelationView relView, String projection)
- {
- int projectionNumber = 0;
- int columnType = 0;
-
- try
- {
- RelationViewMetaData rvmd = relView.getMetaData();
- projectionNumber = relView.findProjByName(projection);
- columnType = rvmd.getColumnType(projectionNumber);
- if ( (columnType == Types.DATE) ||
- (columnType == Types.TIME) ||
- (columnType == Types.TIMESTAMP) )
- {
- m_DynamicUpdateOverride = false;
- }
- relView.bindProj(projectionNumber, this);
- }
- catch (SQLException Ex)
- {
- raiseException(
- "SQLException from setBinding: "
- + Ex.getMessage());
- }
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: setDynamicUpdate //
- // //
- // PURPOSE: //
- // //
- // PARAMETERS: //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- //*************************************************************************//
-
- public void setDynamicUpdate(boolean update)
- {
- m_DynamicUpdate = update;
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: notifyDataChange //
- // //
- // PURPOSE: //
- // Implement the ProjLink interface function, notifyDataChange(). //
- // This function is called when the projection's data changes at //
- // the database. //
- // //
- // PARAMETERS: //
- // @param binder The ProjBinder binder object which this component can use//
- // to get or change data at the database server. //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- // Step 1: set m_ProjBinder equal to binder object //
- // Step 2: synchronize m_BinderData with binder object //
- // Step 3: synchronize m_ScreenData with current screen //
- // Step 4: if the two are different then //
- // - set m_ScreenData equal to m_BinderData to avoid recursion //
- // - call setText to update screen //
- // Step 5: enable or disable editing based on binder //
- // //
- //*************************************************************************//
-
- public void notifyDataChange(ProjBinder binder)
- {
- // STEP 1
- if (binder == null)
- {
- // Raise an exception..
- return;
- }
- m_ProjBinder = binder;
-
- // STEP 2
- try
- {
- if (binder.getRelationView().getCurrentRecordState()
- != Record.RECSTATE_INVALID)
- {
- if (binder.isReadable() && !binder.isNull())
- {
- m_BinderData = binder.getStringValue();
- }
- else
- {
- m_BinderData = "";
- }
- }
- else
- {
- m_BinderData = "";
- }
- }
- catch (SQLException Ex)
- {
- raiseException(
- "SQLException from TextArea.notifyDataChange: "
- + Ex.getMessage());
- }
- catch (java.io.IOException Ex)
- {
- raiseException(
- "IOException from TextArea.notifyDataChange: "
- + Ex.getMessage());
- }
- if (m_BinderData == null)
- {
- m_BinderData = new String();
- }
-
- // STEP 3
- m_ScreenData = getText();
-
- // STEP 4
- if (!m_BinderData.equals(m_ScreenData))
- {
- m_ScreenData = m_BinderData;
- setText(m_ScreenData);
- }
-
- // STEP 5
- if (m_BinderDetermines)
- {
- setEditable(m_ProjBinder);
- }
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: lostFocus //
- // //
- // PURPOSE: Intercept the event to send data to the binder //
- // //
- // PARAMETERS: //
- // @param evt the lost focus event being caught //
- // @param what the object that is losing focus //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // Call notifySetData since that is the standard way of handling //
- // any event that should cause us to send data to the binder. //
- // //
- //*************************************************************************//
-
- public boolean lostFocus(java.awt.Event evt, Object what)
- {
- try
- {
- notifySetData(m_ProjBinder);
- }
- catch (SQLException Ex)
- {
- raiseException(
- "SQLException from TextArea.notifySetData: "
- + Ex.getMessage());
- }
- return super.lostFocus(evt, what);
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: notifyInputChange //
- // //
- // PURPOSE: Handle any event that causes us to send data to binder object //
- // //
- // PARAMETERS: //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- // //
- // Step 1: synchronize m_ScreenData with current screen //
- // Step 2: if m_ScreenData differs from m_BinderData then... //
- // - set m_BinderData equal to m_ScreenData to avoid recursion //
- // - call m_Binder.setString to update binder //
- // //
- //*************************************************************************//
-
- boolean notifyInputChanged(String input)
- {
- // STEP 1
- if (!m_ScreenData.equals(input))
- {
- m_ScreenData = input;
- }
-
- // STEP 2
-
- try{
- if (!m_BinderData.equals(m_ScreenData)
- && (m_ProjBinder.getRelationView().getCurrentRecordState() != Record.RECSTATE_INVALID)
- && (m_ProjBinder.getRelationView().getCurrentRecordState() != Record.RECSTATE_DELETED)
- && (m_ProjBinder.getRelationView().getCurrentRecordState() != Record.RECSTATE_DB_DELETED))
- {
- m_BinderData = m_ScreenData;
- try
- {
- if (m_ProjBinder != null && m_ProjBinder.isWritable())
- {
- m_ProjBinder.setValueFromString(m_ScreenData, 0, m_treatBlankAs);
- }
- }
- catch (java.io.IOException Ex)
- {
- raiseException(
- "IOException from TextArea.notifyInputChange.setString: "
- + Ex.getMessage());
- return false;
- }
- }
- }
- catch (SQLException Ex)
- {
- raiseException(
- "SQLException from TextField.notifyInputChange: "
- + Ex.getMessage());
- return false;
- }
- return true;
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: notifySetData //
- // //
- // PURPOSE: Send data to binder //
- // //
- // PARAMETERS: //
- // @param binder The ProjBinder binder object which this component can use//
- // to change data at the database server. //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- // //
- //*************************************************************************//
-
- public boolean notifySetData(ProjBinder binder) throws SQLException
- {
- return ( notifyInputChanged(getText()) );
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: handleEvent //
- // //
- // PURPOSE: Respond to any event we want to handle ourselves. //
- // //
- // PARAMETERS: //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // * Handles the event. Returns true if the event is handled and //
- // * should not be passed to the parent of this component. The default //
- // * event handler calls some helper methods to make life easier //
- // * on the programmer. //
- // * @param evt the event //
- // * @;see #mouseEnter //
- // * @see #mouseExit //
- // * @see #mouseMove //
- // * @see #mouseDown //
- // * @see #mouseDrag //
- // * @see #mouseUp //
- // * @see #keyDown //
- // * @see #action //
- // //
- //*************************************************************************//
-
- public boolean handleEvent(java.awt.Event evt) {
- // debugPrint(evt.toString());
- if (m_DynamicUpdate && m_DynamicUpdateOverride)
- {
- try
- {
- notifySetData(m_ProjBinder);
- }
- catch (SQLException Ex)
- {
- raiseException(
- "SQLException from TextArea.notifySetData: "
- + Ex.getMessage());
- }
- }
- return super.handleEvent(evt);
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: setEditable //
- // //
- // PURPOSE: Enable or disable input //
- // //
- // PARAMETERS: //
- // @param binder The ProjBinder binder object which this component can use//
- // to change data at the database server. //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- //*************************************************************************//
-
- void setEditable(ProjBinder binder)
- {
- //Disable input if binder is not writeable
- boolean isWritable = false;
-
- try
- {
- if (binder != null)
- {
- RelationView rv = binder.getRelationView();
- if (rv != null && (rv.getCurrentRecordState() != Record.RECSTATE_INVALID))
- {
- isWritable = binder.isWritable();
- }
- }
- }
- catch (SQLException Ex)
- {
- raiseException(
- "SQLException from setEditable: "
- + Ex.getMessage());
- }
- super.setEditable(isWritable);
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: setEditable //
- // //
- // PURPOSE: Set editable attribute //
- // //
- // PARAMETERS: //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- //*************************************************************************//
-
- public void setEditable(boolean value)
- {
- m_BinderDetermines = value;
- super.setEditable(value);
- }
-
- //*************************************************************************//
- // //
- // FUNCTION: raiseException //
- // //
- // PURPOSE: //
- // //
- // PARAMETERS: //
- // //
- // RETURNS: //
- // //
- // COMMENTS: //
- // //
- //*************************************************************************//
-
- void raiseException(String text)
- {
- System.out.println(text);
- }
- }